# @Time : 2020/7/13
# @Author : 大太阳小白
# @Software: PyCharm
# @blog：https://blog.csdn.net/weixin_41579863
from flask import Flask
from config import config
from apps.api import api
from apps.index.view_index import index_blueprint


def create_app(config_name):
    # 初始化
    app = Flask(__name__, template_folder="..\\templates", static_folder="..\\static")

    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config['TEMPLATE_FOLDER'] = 'templates'

    # 导致指定的配置对象:创建app时，传入环境的名称
    app.config.from_object(config[config_name])

    # 注册蓝图,url_prefix为所有路由默认加上的前缀
    app.register_blueprint(api, url_prefix='/api')
    app.register_blueprint(index_blueprint)
    return app

